package com.zto.mybatis.custom2;




import com.zto.mybatis.custom2.config.pojo.User2;
import com.zto.mybatis.custom2.config.MyConfiguration;
import com.zto.mybatis.custom2.config.mappers.User2Mapper;
import com.zto.mybatis.custom2.executor.ExecutorFactory;
import com.zto.mybatis.custom2.executor.SimpleExecutor;
import com.zto.mybatis.custom2.session.MySqlSession;

import java.io.IOException;

/**
 * Created by xingyuchao on 2017-07-09.
 */
public class Main {

    public static void main(String[] args) throws IOException {

        MyConfiguration configuration = new MyConfiguration();
        configuration.scanPath("com.zto.mybatis.custom2.config.mappers");
        configuration.build();
        //MySqlSession sqlSession = new MySqlSession(configuration, new SimpleExecutor());
        MySqlSession sqlSession = new MySqlSession(configuration,
                ExecutorFactory.get(ExecutorFactory.ExecutorType.CACHING.name(),configuration));
        User2Mapper mapper = sqlSession.getMapper(User2Mapper.class);
        long start = System.currentTimeMillis();
        User2 user2 = mapper.selectByPrimaryKey(1);
        System.out.println("cost:"+ (System.currentTimeMillis() -start));
        System.out.println(user2);

        start = System.currentTimeMillis();
        user2 = mapper.selectByPrimaryKey(1);
        System.out.println("cost:"+ (System.currentTimeMillis() -start));
        System.out.println(user2);
    }
}
